<template>
  <div>
    <el-table
      :data="tableData"
      border
      class="bidding"
      ref="add_material"
      :header-cell-style="{ padding: '0px', background: '#F2F3F7' }"
      :row-class-name="tabRowClassName"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="44" align="center"> </el-table-column>
      <el-table-column width="60" align="center" type="index" label="序号">
        <template slot-scope="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column label="材料名称" align="center" prop="materialName" width="160"> </el-table-column>
      <el-table-column label="规格型号" align="center" prop="model" width="160"> </el-table-column>
      <el-table-column label="单位" align="center" prop="company" width="80"> </el-table-column>
      <el-table-column label="参数指标" align="center" prop="parameterIndex" width="160"> </el-table-column>
      <el-table-column label="品牌产地" align="center" prop="brandOrigin" width="160"> </el-table-column>
      <el-table-column label="数量" align="center" prop="purchaseQuantity" width="120"> </el-table-column>
      <el-table-column label="单价" align="center" prop="unitPrice" width="120"> </el-table-column>
      <el-table-column label="税率(%)" align="center" prop="taxRate" width="80"> </el-table-column>
      <el-table-column label="不含税金额" align="center" prop="excludingTax" width="140"> </el-table-column>
      <el-table-column label="税金" align="center" prop="taxes" width="140"> </el-table-column>
      <el-table-column label="价税合计" align="center" prop="totalPrice" width="160" fixed="right"> </el-table-column>
    </el-table>
    <div class="footer">
      <el-button size="small" class="commonBtn" @click="closeBtn">取消</el-button>
      <el-button size="small" class="commonBtn1" @click="subBtn">确定</el-button>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [],
      selectList: []
    }
  },
  props: {
    contractId: {
      type: [String, Number],
      require: true
    }
  },
  mounted() {
    this.getData()
  },
  methods: {
    closeBtn() {
      this.$emit('close', '')
    },
    subBtn() {
      if (this.selectList.length == 0) {
        this.$message.error('请选择材料')
      } else {
        this.$emit('close', this.selectList)
      }
    },
    tabRowClassName({ row, rowIndex }) {
      let index = rowIndex + 1
      if (index % 2 == 0) {
        return 'warning-row'
      }
    },
    handleSelectionChange(val) {
      this.selectList = val
    },
    getData() {
      this.$https({
        method: 'post',
        url: '/contract/queryContractPurchaseList',
        data: {
          id: this.contractId,
          productTypes: 1
        }
      })
        .then(res => {
          if (res.code === 0) {
            this.tableData = res.data
          } else {
            this.$message.error(res.msg)
          }
        })
        .catch(err => {
          console.log(err)
        })
    }
  }
}
</script>
<style lang="less" scoped>
.footer {
  text-align: center;
  margin-top: 40px;
}
</style>
